package com.dgty.dg_common.widget

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.dgty.dg_common.R

/**
 * Title: TopbarView$
 * Description:
 *
 * Created DateTime: 2023/2/10$ 17:22$
 * Created by cacif$.
 */
class TopbarView(context: Context?) : LinearLayout(context) {
    lateinit var view: View
    lateinit var backImg: ImageView
    lateinit var titleTv: TextView
    lateinit var rightTv: TextView
    init {
        initView()
    }

    private fun initView() {
        view = LayoutInflater.from(context).inflate(R.layout.view_topbar, this, true)
        backImg = view.findViewById(R.id.img_back)
        titleTv = view.findViewById(R.id.tv_title)
        rightTv = view.findViewById(R.id.tv_right)
    }

    fun setTitle(title: String) {
        titleTv.text = title
    }

    fun setRightValue(value: String) {
        rightTv.text = value
    }

    interface OnButtonClickListener{
        fun onLeftClick()
        fun onRightClick()
    }

    /**
     * 点击事件
     */
    fun setOnButtonClickListener(onButtonClickListener: OnButtonClickListener) {

        backImg.setOnClickListener { onButtonClickListener.onLeftClick() }

        rightTv.setOnClickListener { onButtonClickListener.onRightClick() }
    }
}